<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        /**
         * String字符串
         */ 
        var str = "  hello world "
        // console.log(str.length)
        // console.log(str.charAt(1))
        // console.log(str.indexOf('o'))
        // console.log(str.lastIndexOf('o'))
        // console.log(str.toLowerCase())
        // console.log(str.toUpperCase())
        // console.log(str.substring(1,7))
        // console.log(str.replace('o','4'))
        // console.log(str.split(' '))
        // console.log(str.trim())


        /**
         * Date日期
         */ 
        var today = new Date()
        console.log(today)

        var year = today.getFullYear()
        var month = checkNum(today.getMonth()+1)
        var date = checkNum(today.getDate())
        var hour = checkNum(today.getHours())
        var minute = checkNum(today.getMinutes())
        var second = checkNum(today.getSeconds())
        var milliSeconds = today.getMilliseconds()
        var day = today.getDay()
        var weekday = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']

        // var currentTime = year + '-' + month + '-' + date + ' ' + hour + ':' + minute + ':' + second + ' ' + weekday[day]

        // 使用模板字符串
        var currentTime = `${year}-${month}-${date} ${hour}:${minute}:${second} ${weekday[day]}`



        console.log(currentTime)

        
        function checkNum(num){
            return num<=9 ? '0'+num : num
        }


        /**
         * JSON 对象
         */ 
        var stu = {
            "id": 1001,
            "name": "alice",
            "age": 18,
            "height": 180.4,
            "address": {
                "province": "江苏",
                "city": "南京市",
                "district": "秦淮区",
                "street": "秦虹街道"
            }
        }
        console.log(stu.name, stu.age, stu.height, stu.address.city)

        // json对象数组
        var users = [
            {
                "id": 101,
                "username": "admin",
                "password": "123",
                "state": 1
            },
            {
                "id": 102,
                "username": "jack",
                "password": "111",
                "state": 0
            },
            {
                "id": 103,
                "username": "lucy",
                "password": "222",
                "state": 1
            }
        ]

        for(var u of users){
            console.log(u.id, u.username, u.password, u.state)
        }


        /**
         * JSON对象和字符串之间的转换
         */ 
        // JSON对象 ------> 字符串
        var person={
            "name":"汤小洋",
            "age":18,
            "height":180.5
        }
        // console.log(typeof person)
        // console.log(person)

        // var str = JSON.stringify(person)
        // console.log(str)
        // console.log(typeof str)

        // 字符串 ------> JSON对象
        var str='{"name":"tom","age":20}';
        var obj = JSON.parse(str)
        console.log(obj.name)


        /**
         * 对象字面量
         */ 
        var customer = {
            name: '张三',
            age: 20,
            height: 190.5,
            study: function(){
                console.log('客户正在学习。。。。。')
            }
        }
        console.log(customer.name, customer.age)
        customer.study()


        var s = '{name:"李四",age:22}'
        // console.log(JSON.parse(s))

    </script>
</head>
<body>
    
</body>
</html>